home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / awt / MenuItem.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  6.1 KB  |  306 lines

  1. package java.awt;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.peer.MenuItemPeer;
  7. import java.io.IOException;
  8. import java.io.ObjectInputStream;
  9. import java.io.ObjectOutputStream;
  10. import java.util.EventListener;
  11. import javax.accessibility.Accessible;
  12. import javax.accessibility.AccessibleContext;
  13.  
  14. public class MenuItem extends MenuComponent implements Accessible {
  15.    boolean enabled;
  16.    String label;
  17.    String actionCommand;
  18.    long eventMask;
  19.    transient ActionListener actionListener;
  20.    private MenuShortcut shortcut;
  21.    private static final String base = "menuitem";
  22.    private static int nameCounter;
  23.    private static final long serialVersionUID = -21757335363267194L;
  24.    private int menuItemSerializedDataVersion;
  25.  
  26.    public MenuItem() throws HeadlessException {
  27.       this("", (MenuShortcut)null);
  28.    }
  29.  
  30.    public MenuItem(String var1) throws HeadlessException {
  31.       this(var1, (MenuShortcut)null);
  32.    }
  33.  
  34.    public MenuItem(String var1, MenuShortcut var2) throws HeadlessException {
  35.       this.enabled = true;
  36.       this.shortcut = null;
  37.       this.menuItemSerializedDataVersion = 1;
  38.       this.label = var1;
  39.       this.shortcut = var2;
  40.    }
  41.  
  42.    String constructComponentName() {
  43.       synchronized(this.getClass()) {
  44.          return "menuitem" + nameCounter++;
  45.       }
  46.    }
  47.  
  48.    public void addNotify() {
  49.       synchronized(this.getTreeLock()) {
  50.          if (this.peer == null) {
  51.             this.peer = Toolkit.getDefaultToolkit().createMenuItem(this);
  52.          }
  53.  
  54.       }
  55.    }
  56.  
  57.    public String getLabel() {
  58.       return this.label;
  59.    }
  60.  
  61.    public synchronized void setLabel(String var1) {
  62.       this.label = var1;
  63.       MenuItemPeer var2 = (MenuItemPeer)this.peer;
  64.       if (var2 != null) {
  65.          var2.setLabel(var1);
  66.       }
  67.  
  68.    }
  69.  
  70.    public boolean isEnabled() {
  71.       return this.enabled;
  72.    }
  73.  
  74.    public synchronized void setEnabled(boolean var1) {
  75.       this.enable(var1);
  76.    }
  77.  
  78.    /** @deprecated */
  79.    @Deprecated
  80.    public synchronized void enable() {
  81.       this.enabled = true;
  82.       MenuItemPeer var1 = (MenuItemPeer)this.peer;
  83.       if (var1 != null) {
  84.          var1.enable();
  85.       }
  86.  
  87.    }
  88.  
  89.    /** @deprecated */
  90.    @Deprecated
  91.    public void enable(boolean var1) {
  92.       if (var1) {
  93.          this.enable();
  94.       } else {
  95.          this.disable();
  96.       }
  97.  
  98.    }
  99.  
  100.    /** @deprecated */
  101.    @Deprecated
  102.    public synchronized void disable() {
  103.       this.enabled = false;
  104.       MenuItemPeer var1 = (MenuItemPeer)this.peer;
  105.       if (var1 != null) {
  106.          var1.disable();
  107.       }
  108.  
  109.    }
  110.  
  111.    public MenuShortcut getShortcut() {
  112.       return this.shortcut;
  113.    }
  114.  
  115.    public void setShortcut(MenuShortcut var1) {
  116.       this.shortcut = var1;
  117.       MenuItemPeer var2 = (MenuItemPeer)this.peer;
  118.       if (var2 != null) {
  119.          var2.setLabel(this.label);
  120.       }
  121.  
  122.    }
  123.  
  124.    public void deleteShortcut() {
  125.       this.shortcut = null;
  126.       MenuItemPeer var1 = (MenuItemPeer)this.peer;
  127.       if (var1 != null) {
  128.          var1.setLabel(this.label);
  129.       }
  130.  
  131.    }
  132.  
  133.    void deleteShortcut(MenuShortcut var1) {
  134.       if (var1.equals(this.shortcut)) {
  135.          this.shortcut = null;
  136.          MenuItemPeer var2 = (MenuItemPeer)this.peer;
  137.          if (var2 != null) {
  138.             var2.setLabel(this.label);
  139.          }
  140.       }
  141.  
  142.    }
  143.  
  144.    void doMenuEvent(long var1, int var3) {
  145.       Toolkit.getEventQueue().postEvent(new ActionEvent(this, 1001, this.getActionCommand(), var1, var3));
  146.    }
  147.  
  148.    private final boolean isItemEnabled() {
  149.       if (!this.isEnabled()) {
  150.          return false;
  151.       } else {
  152.          MenuContainer var1 = this.getParent_NoClientCode();
  153.  
  154.          while(var1 instanceof Menu) {
  155.             Menu var2 = (Menu)var1;
  156.             if (!var2.isEnabled()) {
  157.                return false;
  158.             }
  159.  
  160.             var1 = var2.getParent_NoClientCode();
  161.             if (var1 == null) {
  162.                return true;
  163.             }
  164.          }
  165.  
  166.          return true;
  167.       }
  168.    }
  169.  
  170.    boolean handleShortcut(KeyEvent var1) {
  171.       MenuShortcut var2 = new MenuShortcut(var1.getKeyCode(), (var1.getModifiers() & 1) > 0);
  172.       if (var2.equals(this.shortcut) && this.isItemEnabled()) {
  173.          if (var1.getID() == 401) {
  174.             this.doMenuEvent(var1.getWhen(), var1.getModifiers());
  175.          }
  176.  
  177.          return true;
  178.       } else {
  179.          return false;
  180.       }
  181.    }
  182.  
  183.    MenuItem getShortcutMenuItem(MenuShortcut var1) {
  184.       return var1.equals(this.shortcut) ? this : null;
  185.    }
  186.  
  187.    protected final void enableEvents(long var1) {
  188.       this.eventMask |= var1;
  189.       this.newEventsOnly = true;
  190.    }
  191.  
  192.    protected final void disableEvents(long var1) {
  193.       this.eventMask &= ~var1;
  194.    }
  195.  
  196.    public void setActionCommand(String var1) {
  197.       this.actionCommand = var1;
  198.    }
  199.  
  200.    public String getActionCommand() {
  201.       return this.getActionCommandImpl();
  202.    }
  203.  
  204.    final String getActionCommandImpl() {
  205.       return this.actionCommand == null ? this.label : this.actionCommand;
  206.    }
  207.  
  208.    public synchronized void addActionListener(ActionListener var1) {
  209.       if (var1 != null) {
  210.          this.actionListener = AWTEventMulticaster.add(this.actionListener, var1);
  211.          this.newEventsOnly = true;
  212.       }
  213.    }
  214.  
  215.    public synchronized void removeActionListener(ActionListener var1) {
  216.       if (var1 != null) {
  217.          this.actionListener = AWTEventMulticaster.remove(this.actionListener, var1);
  218.       }
  219.    }
  220.  
  221.    public synchronized ActionListener[] getActionListeners() {
  222.       return (ActionListener[])this.getListeners(ActionListener.class);
  223.    }
  224.  
  225.    public <T extends EventListener> T[] getListeners(Class<T> var1) {
  226.       ActionListener var2 = null;
  227.       if (var1 == ActionListener.class) {
  228.          var2 = this.actionListener;
  229.       }
  230.  
  231.       return (T[])AWTEventMulticaster.getListeners(var2, var1);
  232.    }
  233.  
  234.    protected void processEvent(AWTEvent var1) {
  235.       if (var1 instanceof ActionEvent) {
  236.          this.processActionEvent((ActionEvent)var1);
  237.       }
  238.  
  239.    }
  240.  
  241.    boolean eventEnabled(AWTEvent var1) {
  242.       if (var1.id == 1001) {
  243.          return (this.eventMask & 128L) != 0L || this.actionListener != null;
  244.       } else {
  245.          return super.eventEnabled(var1);
  246.       }
  247.    }
  248.  
  249.    protected void processActionEvent(ActionEvent var1) {
  250.       ActionListener var2 = this.actionListener;
  251.       if (var2 != null) {
  252.          var2.actionPerformed(var1);
  253.       }
  254.  
  255.    }
  256.  
  257.    public String paramString() {
  258.       String var1 = ",label=" + this.label;
  259.       if (this.shortcut != null) {
  260.          var1 = var1 + ",shortcut=" + this.shortcut;
  261.       }
  262.  
  263.       return super.paramString() + var1;
  264.    }
  265.  
  266.    private void writeObject(ObjectOutputStream var1) throws IOException {
  267.       var1.defaultWriteObject();
  268.       AWTEventMulticaster.save(var1, "actionL", this.actionListener);
  269.       var1.writeObject((Object)null);
  270.    }
  271.  
  272.    private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException, HeadlessException {
  273.       var1.defaultReadObject();
  274.  
  275.       Object var2;
  276.       while(null != (var2 = var1.readObject())) {
  277.          String var3 = ((String)var2).intern();
  278.          if ("actionL" == var3) {
  279.             this.addActionListener((ActionListener)var1.readObject());
  280.          } else {
  281.             var1.readObject();
  282.          }
  283.       }
  284.  
  285.    }
  286.  
  287.    private static native void initIDs();
  288.  
  289.    public AccessibleContext getAccessibleContext() {
  290.       if (this.accessibleContext == null) {
  291.          this.accessibleContext = new AccessibleAWTMenuItem(this);
  292.       }
  293.  
  294.       return this.accessibleContext;
  295.    }
  296.  
  297.    static {
  298.       Toolkit.loadLibraries();
  299.       if (!GraphicsEnvironment.isHeadless()) {
  300.          initIDs();
  301.       }
  302.  
  303.       nameCounter = 0;
  304.    }
  305. }
  306.